exports.creatingChatRooms = function (req, res) {

    //获取参数信息
    var bodyParams = req.routeInfo.bodyParams;

    //如果存在，返回的主键id
    var cr_id = "";

    //返回结果
    var resultData = {};

    //该聊天室是否已经存在
    var isExistence = false

    //任务流创建
    async.waterfall([

        //检查是否存在这个聊天室
        //添加或更新聊天室信息到数据库
        //添加或更新聊天室信息到socket全局变量
        (cb) => {
            db.field('cr_id,cr_name,cr_create_userid').where({
                "cr_room_id" : bodyParams.chatName,
                "cr_nid"     :bodyParams.severAppId,
            }).select("socket_chat_room",(rs)=>{

                if(rs.length != 0){
                    isExistence = true
                    resultData.name              = rs[0].cr_name
                    resultData.cr_create_userid  = rs[0].cr_create_userid
                }
                cb()
            })
        },
        (cb) => {

            if(isExistence){
                //更新
                db.where({
                    "cr_room_id" : bodyParams.chatName,

                }).update({
                    "cr_name"           :bodyParams.name,
                    "cr_create_userid"  :bodyParams.masterName,
                    "cr_is_delete"      : 0
                },"socket_chat_room",(rs)=>{
                    cb()
                })
            }else{
                //添加
                db.add({
                    "cr_name"           :bodyParams.name,
                    "cr_create_userid"  :bodyParams.masterName,
                    "cr_room_id"        :bodyParams.chatName,
                    "cr_nid"            :bodyParams.severAppId,
                    "cr_create_time"    :common.nowTime(),
                },"socket_chat_room",(rs)=>{
                    resultData.cr_room_name         = bodyParams.chatName
                    resultData.name                 = bodyParams.name
                    resultData.cr_create_userName   = bodyParams.masterName
                    cb()
                })
            }

        },
        (cb) => {
            var data =  bodyParams
            socketObj._createRoom(data,(isTrue) => {
                cb()
            })
        }

    ],()=> {

        //返回最终拼接结果
        RES.successResponse(res,resultData);

    });
    
}